package com.example.asus.picselector.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.example.asus.picselector.adapter.PhotoPagerAdapter;
import com.example.asus.picselector.R;

import java.util.ArrayList;

public class PhotoViewActivity extends BaseActivity {

    private ViewPager viewPager;
    private int currentPosition;
    private TextView mTvImageCount;
    private ArrayList<String> Urls;

    @Override
    protected void setContentView() {
      setContentView(R.layout.activity_photo_view);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        initView();
        initData();
    }

    private void initView() {
        viewPager = findViewById(R.id.view_pager_photo);
        mTvImageCount = findViewById(R.id.tv_image_count);
    }

    private void initData() {
        Intent intent = getIntent();
        currentPosition = intent.getIntExtra("currentPosition", 0);
        Urls = intent.getStringArrayListExtra("dataBean");

        PhotoPagerAdapter adapter = new PhotoPagerAdapter(getSupportFragmentManager(), Urls);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(currentPosition);
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
                mTvImageCount.setText(String.valueOf(position + 1) + "/" + Urls.size());
            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

}
